package com.lanou.sfu.songforu.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.sfu.songforu.music_library_fragment.ArtistFragment;
import com.lanou.sfu.songforu.music_library_fragment.RadioFragment;
import com.lanou.sfu.songforu.music_library_fragment.RankFragment;
import com.lanou.sfu.songforu.music_library_fragment.SongMenuFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 15/10/21.
 */
public class MusicLibraryAdapter extends FragmentPagerAdapter {
    private ArrayList<Fragment> fragmentList;
    private String[] titleList = {"歌手", "排行榜", "歌单", "电台"};


    private void init() {
        fragmentList = new ArrayList<>();
        fragmentList.add(new ArtistFragment());
        fragmentList.add(new RankFragment());
//        fragmentList.add(new SongMenuFragment());
        fragmentList.add(new SongMenuFragment());
        fragmentList.add(new RadioFragment());
    }

    public ArrayList getFragmentList() {
        return fragmentList;
    }

    public MusicLibraryAdapter(FragmentManager fm) {
        super(fm);
        init();
    }

    @Override
    public Fragment getItem(int position) {
//        init();
        Fragment fragment = fragmentList.get(position);
//        fragmentList.add(fragment);
        return fragment;
    }

    @Override
    public int getCount() {
        return titleList.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleList[position];
    }
}
